using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace LMSData
{
	/// <summary>
	/// Strongly-typed collection for the CourseGroupMap class.
	/// </summary>
	[Serializable]
	public partial class CourseGroupMapCollection : ActiveList<CourseGroupMap, CourseGroupMapCollection> 
	{	   
		public CourseGroupMapCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CourseGroupMap table.
	/// </summary>
	[Serializable]
	public partial class CourseGroupMap : ActiveRecord<CourseGroupMap>
	{
		#region .ctors and Default Settings
		
		public CourseGroupMap()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public CourseGroupMap(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public CourseGroupMap(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public CourseGroupMap(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CourseGroupMap", TableType.Table, DataService.GetInstance("LMS"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarCourseID = new TableSchema.TableColumn(schema);
				colvarCourseID.ColumnName = "CourseID";
				colvarCourseID.DataType = DbType.Int32;
				colvarCourseID.MaxLength = 0;
				colvarCourseID.AutoIncrement = false;
				colvarCourseID.IsNullable = false;
				colvarCourseID.IsPrimaryKey = true;
				colvarCourseID.IsForeignKey = true;
				colvarCourseID.IsReadOnly = false;
				colvarCourseID.DefaultSetting = @"";
				
					colvarCourseID.ForeignKeyTableName = "Course";
				schema.Columns.Add(colvarCourseID);
				
				TableSchema.TableColumn colvarGroupID = new TableSchema.TableColumn(schema);
				colvarGroupID.ColumnName = "GroupID";
				colvarGroupID.DataType = DbType.Int32;
				colvarGroupID.MaxLength = 0;
				colvarGroupID.AutoIncrement = false;
				colvarGroupID.IsNullable = false;
				colvarGroupID.IsPrimaryKey = true;
				colvarGroupID.IsForeignKey = true;
				colvarGroupID.IsReadOnly = false;
				colvarGroupID.DefaultSetting = @"";
				
					colvarGroupID.ForeignKeyTableName = "Group";
				schema.Columns.Add(colvarGroupID);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["LMS"].AddSchema("CourseGroupMap",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("CourseID")]
		public int CourseID 
		{
			get { return GetColumnValue<int>("CourseID"); }

			set { SetColumnValue("CourseID", value); }

		}

		  
		[XmlAttribute("GroupID")]
		public int GroupID 
		{
			get { return GetColumnValue<int>("GroupID"); }

			set { SetColumnValue("GroupID", value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Course ActiveRecord object related to this CourseGroupMap
		/// 
		/// </summary>
		public LMSData.Course Course
		{
			get { return LMSData.Course.FetchByID(this.CourseID); }

			set { SetColumnValue("CourseID", value.CourseID); }

		}

		
		
		/// <summary>
		/// Returns a Group ActiveRecord object related to this CourseGroupMap
		/// 
		/// </summary>
		public LMSData.Group Group
		{
			get { return LMSData.Group.FetchByID(this.GroupID); }

			set { SetColumnValue("GroupID", value.GroupID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varCourseID,int varGroupID)
		{
			CourseGroupMap item = new CourseGroupMap();
			
			item.CourseID = varCourseID;
			
			item.GroupID = varGroupID;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varCourseID,int varGroupID)
		{
			CourseGroupMap item = new CourseGroupMap();
			
				item.CourseID = varCourseID;
				
				item.GroupID = varGroupID;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string CourseID = @"CourseID";
			 public static string GroupID = @"GroupID";
						
		}

		#endregion
	}

}

